package com.yanqu.road.server.manger;

import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.game.message.SequentialMessageExecuter;
import com.yanqu.road.server.protocol.Protocol;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SequentialMessageExecuterMgr extends TempMgr {
    private static Map<Integer, SequentialMessageExecuter> executerMap = new ConcurrentHashMap<>();
    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }

    /**
    * 描述：是否顺序处理消息
    * 作者：zrq
    * 时间：2023/7/3
    * 参数：

    * 返回值：
    **/
    public static boolean isSequentialMessage(int code){
        if(Protocol.S_CROSS_UNION_BROADCAST_FROM_CROSS == code){
            return true;
        }
        return false;
    }

    /**
    * 描述：获取顺序消息执行器
    * 作者：zrq
    * 时间：2023/7/3
    * 参数：

    * 返回值：
    **/
    public static SequentialMessageExecuter getSequentialMessageExecuter(int code){
        if(!isSequentialMessage(code)){
            return null;
        }
        if(!executerMap.containsKey(code)){
            synchronized (executerMap){
                if(!executerMap.containsKey(code)){
                    SequentialMessageExecuter executer = new SequentialMessageExecuter();
                    executerMap.put(code, executer);
                }
            }
        }
        return executerMap.get(code);
    }
}
